<?php

define('IN_API', true);
require_once '../../framework/bootstrap.inc.php';
require_once 'defines.php';
$apikey = $_GPC['apikey'];
$id = $_GPC['id'];
$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" => $id));
$settings = unserialize($settings['settings']);

$now_time = time();
if(intval($_GPC['d'])){
	$start_time = $now_time - intval($_GPC['d']) * 24 * 60 * 60;
}else{
	$start_time = $now_time - 1 * 24 * 60 * 60;
}

$end_time = $now_time;
//获取美团推广链接
$postdata = http_build_query(array('apikey' => $settings['ddxapikey'],'start_time' => $start_time,'end_time' => $end_time,'query_type' => 2));
$options = array(
	'http' => array(
	'method' => 'POST',
	'header' => 'Content-type:application/x-www-form-urlencoded',
	'content' => $postdata,
	'timeout' => 1 * 60 // 超时时间（单位:s）
  )
);
$cxContext = stream_context_create($options);
$res = file_get_contents("http://api.tbk.dingdanxia.com/waimai/meituan_orders", false, $cxContext);

$res = json_decode($res,true);
if($res['code'] == 200){
	$total_results = $res['total_results'];
	$total_pages = ceil($res['total_results'] / 20);
	foreach ($res['data'] as $k => $v) {
		if(!$v['paytime']){
				continue;
			}
		if($v['type'] == 4){$pingtai_name = '美团外卖';}elseif($v['type'] == 6){$pingtai_name = '美团闪购';}elseif($v['type'] == 8){$pingtai_name = '美团优选';}
		if($settings['system_type'] == 1){
			$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => $v['orderid'], "system_id" => $settings['system_id']));
			if($order){
				if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
				$fee = fee($order['c_1_uid'],$id);
				if($v['status'] == 8){
					pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "system_id" => $settings['system_id'] , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
				}else{
					if($v['status'] == 9){$v['profit'] = 0;}
					pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "system_id" => $settings['system_id'] , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
				}
			}else{
				$u = pdo_get(MODULE_NAME."_user_u", array("uid" => $v['sid'] , "system_id" => $settings['system_id']));
				if($u){
					$fee = fee($u['uid'],$id);
				}else{
					$fee = fee('000000',$id);
				}
				$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
				
				$resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "system_id" => $settings['system_id'] , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
				if($resin){
				  orderNotify($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
				}
			}
		}else{
			$order = pdo_get(MODULE_NAME."_order", array("order_id" => $v['orderid'] , "uniacid" => $id));
			if($order){
				if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
				$fee = fee($order['c_1_uid'],$id);
				if($v['status'] == 8){
					pdo_update(MODULE_NAME."_order", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
				}else{
					
					if($v['status'] == 9){$v['profit'] = 0;}
					pdo_update(MODULE_NAME."_order", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
				}
				
				
			}else{
				$u = pdo_get(MODULE_NAME."_user", array("uid" => $v['sid'] , "uniacid" => $id));
				if($u){
					$fee = fee($u['uid'],$id);
				}else{
					$fee = fee('000000',$id);
				}
				$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
				$resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
				if($resin){
				  orderNotify($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
				}
				
			}
		}
		
	}
	if($total_pages > 1){
		for ($x=2; $x<=$total_pages; $x++) {
			$postdata = http_build_query(array('apikey' => $settings['ddxapikey'],'start_time' => $start_time,'end_time' => $end_time,'page' => $x));
			$options = array(
				'http' => array(
				'method' => 'POST',
				'header' => 'Content-type:application/x-www-form-urlencoded',
				'content' => $postdata,
				'timeout' => 1 * 60 // 超时时间（单位:s）
			  )
			);
			$cxContext = stream_context_create($options);
			$res = file_get_contents("http://api.tbk.dingdanxia.com/waimai/meituan_orders", false, $cxContext);
			
			$res = json_decode($res,true);
			if($res['code'] == 200){
				foreach ($res['data'] as $k => $v) {
					if(!$v['paytime']){
						continue;
					}
					if($v['type'] == 4){$pingtai_name = '美团外卖';}elseif($v['type'] == 6){$pingtai_name = '美团闪购';}elseif($v['type'] == 8){$pingtai_name = '美团优选';}
					if($settings['system_type'] == 1){
						$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => $v['orderid'], "system_id" => $settings['system_id']));
						if($order){
							if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
							$fee = fee($order['c_1_uid'],$id);
							if($v['status'] == 8){
								pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "system_id" => $settings['system_id'] , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
							}else{
								if($v['status'] == 9){$v['profit'] = 0;}
								pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "system_id" => $settings['system_id'] , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
							}
							
						}else{
							$u = pdo_get(MODULE_NAME."_user_u", array("uid" => $v['sid'] , "system_id" => $settings['system_id']));
							if($u){
								$fee = fee($u['uid'],$id);
							}else{
								$fee = fee('000000',$id);
							}
							$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
							$resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "system_id" => $settings['system_id'] , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
							if($resin){
							  orderNotify($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
							}
						}
					}else{
						$order = pdo_get(MODULE_NAME."_order", array("order_id" => $v['orderid'] , "uniacid" => $id));
						if($order){
							if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
							$fee = fee($order['c_1_uid'],$id);
							if($v['status'] == 8){
								pdo_update(MODULE_NAME."_order", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
							}else{
								if($v['status'] == 9){$v['profit'] = 0;}
								pdo_update(MODULE_NAME."_order", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
							}
							
						}else{
							$u = pdo_get(MODULE_NAME."_user", array("uid" => $v['sid'] , "uniacid" => $id));
							if($u){
								$fee = fee($u['uid'],$id);
							}else{
								$fee = fee('000000',$id);
							}
							$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
							$resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'meituan' , "pingtai_name" => $pingtai_name , "order_type" => $v['type'] , "order_id" => $v['orderid'] , "order_paid_time" => $v['paytime'] , "order_price" => $v['payprice'] , "order_profit" => $v['profit'] , "goods_title" => $v['smstitle'] , "sid" => $v['sid'] , "order_create_time" => strtotime($v['create_time']) , "order_status" => $v['status'] , "uniacid" => $id , "c_1" => round($v['profit'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['profit'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['profit'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['profit'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['profit'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['profit'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['profit'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['profit'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['profit'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
							if($resin){
							  orderNotify($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
							}
						}
					}
				}
			}
		}
	}
}
if($settings['meituangroup_AppKey']){
	$utmSource = $settings['meituangroup_utmSource'];
	$key = $settings['meituangroup_AppKey'];
	$promotionId = $settings['meituangroup_pid'];
	$timestamp = time();
	$requestId = $utmSource . $timestamp;
	$accessToken = aesencrypt($requestId,$key);

	$startAddDate = date('Y-m-d H:i:s',$start_time);
	$endAddDate = date('Y-m-d H:i:s',$end_time);

	$url = "https://union.dianping.com/data/promote/verify/item?timestamp=" . $timestamp . "&requestId=" . $requestId . "&utmSource=" . $utmSource . "&startAddDate=" . urlencode($startAddDate) . "&endAddDate=" . urlencode($endAddDate) . "&promotionId=" . $promotionId . "&page=1&size=50&version=2.0&accessToken=" . $accessToken;
	$res = ihttp_get($url);
	$res = json_decode($res["content"], true);

	if(count($res['msg']['records']) > 0){
		
		$total_results = $res['msg']['recordCount'];
		$total_pages = ceil($res['msg']['recordCount'] / $res['msg']['pageSize']);
		foreach ($res['msg']['records'] as $k => $v) {
			if($v['orderType'] == '团单'){$pingtai_name = '美团团购';}elseif($v['orderType'] == '外卖'){$pingtai_name = '美团外卖';}elseif($v['orderType'] == '闪购'){$pingtai_name = '美团闪购';}elseif($v['orderType'] == '酒店'){$pingtai_name = '美团酒店';}
			if($settings['system_type'] == 1){
				$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => $v['orderId'], "system_id" => $settings['system_id']));
				if($order){
					if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
					$fee = fee($order['c_1_uid'],$id);
					if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
				}else{
					$u = pdo_get(MODULE_NAME."_user_u", array("utmMedium" => $v['utmMedium'] , "system_id" => $settings['system_id']));
					if($u){
						$fee = fee($u['uid'],$id);
					}else{
						$fee = fee('000000',$id);
					}
					$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					$resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "uniacid" => $id , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
					if($resin){
						orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
					}
				}
			}else{
				$order = pdo_get(MODULE_NAME."_order", array("order_id" => $v['orderId'] , "uniacid" => $id));
				if($order){
					if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
					$fee = fee($order['c_1_uid'],$id);
					if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					pdo_update(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "uniacid" => $id , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
				}else{
					$u = pdo_get(MODULE_NAME."_user", array("utmMedium" => $v['utmMedium'] , "uniacid" => $id));
					if($u){
						$fee = fee($u['uid'],$id);
					}else{
						$fee = fee('000000',$id);
					}
					$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
					if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					$resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "uniacid" => $id  , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
					if($resin){
					  orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
					}
				}
			}
		}
		if($total_pages > 1){
			for ($x=2; $x<=$total_pages; $x++) {

				$url = "https://union.dianping.com/data/promote/verify/item?timestamp=" . $timestamp . "&requestId=" . $requestId . "&utmSource=" . $utmSource . "&startAddDate=" . urlencode($startAddDate) . "&endAddDate=" . urlencode($endAddDate) . "&page=".$x."&size=50&version=2.0&accessToken=" . $accessToken;
				$res = ihttp_get($url);
				$res = json_decode($res["content"], true);

				if(count($res['msg']['records']) > 0){
					foreach ($res['msg']['records'] as $k => $v) {
						if($v['orderType'] == '团单'){$pingtai_name = '美团团购';}elseif($v['orderType'] == '外卖'){$pingtai_name = '美团外卖';}elseif($v['orderType'] == '闪购'){$pingtai_name = '美团闪购';}elseif($v['orderType'] == '酒店'){$pingtai_name = '美团酒店';}
						if($settings['system_type'] == 1){
							$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => $v['orderId'], "system_id" => $settings['system_id']));
							if($order){
								if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
								$fee = fee($order['c_1_uid'],$id);
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "billingDate" => $v['billingDate'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
							}else{
								$u = pdo_get(MODULE_NAME."_user_u", array("utmMedium" => $v['utmMedium'] , "system_id" => $settings['system_id']));
								if($u){
									$fee = fee($u['uid'],$id);
								}else{
									$fee = fee('000000',$id);
								}
								$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								$resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "billingDate" => $v['billingDate'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "uniacid" => $id , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
								if($resin){
								  orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
								}
							}
						}else{
							$order = pdo_get(MODULE_NAME."_order", array("order_id" => $v['orderId'] , "uniacid" => $id));
							if($order){
								if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
								$fee = fee($order['c_1_uid'],$id);
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								pdo_update(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "billingDate" => $v['billingDate'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "uniacid" => $id , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
							}else{
								$u = pdo_get(MODULE_NAME."_user", array("utmMedium" => $v['utmMedium'] , "uniacid" => $id));
								if($u){
									$fee = fee($u['uid'],$id);
								}else{
									$fee = fee('000000',$id);
								}
								$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								$resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "billingDate" => $v['billingDate'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "uniacid" => $id  , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
								if($resin){
									orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
								}
							}
						}
					}
				}
			}
		}
	}



	//核销时间
	if($settings['system_type'] == 1){
		$maxmin = pdo_fetch("select MAX(billingDate) as billingDate_max,MIN(billingDate) as billingDate_min from " . tablename(MODULE_NAME."_order_u") . " where pingtai='fenxiao' and billingDate !='' and order_status != 8 and order_status != 9 and system_id = ".$settings['system_id']);
	}else{
		$maxmin = pdo_fetch("select MAX(billingDate) as billingDate_max,MIN(billingDate) as billingDate_min from " . tablename(MODULE_NAME."_order") . " where pingtai='fenxiao'  and billingDate !='' and order_status != 8 and order_status != 9 and uniacid = ".$id);
	}
	$url = "https://union.dianping.com/data/promote/verify/item?timestamp=" . $timestamp . "&requestId=" . $requestId . "&utmSource=" . $utmSource . "&queryType=4&startTime=" . urlencode($maxmin['billingDate_min']) . "&endTime=" . urlencode($maxmin['billingDate_max']) . "&promotionId=" . $promotionId . "&page=1&size=50&itemBizStatusList=3&version=2.0&accessToken=" . $accessToken;
	$res = ihttp_get($url);
	$res = json_decode($res["content"], true);

	if(count($res['msg']['records']) > 0){
		
		$total_results = $res['msg']['recordCount'];
		$total_pages = ceil($res['msg']['recordCount'] / $res['msg']['pageSize']);
		foreach ($res['msg']['records'] as $k => $v) {
			if($v['orderType'] == '团单'){$pingtai_name = '美团团购';}elseif($v['orderType'] == '外卖'){$pingtai_name = '美团外卖';}elseif($v['orderType'] == '闪购'){$pingtai_name = '美团闪购';}elseif($v['orderType'] == '酒店'){$pingtai_name = '美团酒店';}
			if($settings['system_type'] == 1){
				$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => $v['orderId'], "system_id" => $settings['system_id']));
				if($order){
					if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
					$fee = fee($order['c_1_uid'],$id);
					if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
				}else{
					$u = pdo_get(MODULE_NAME."_user_u", array("utmMedium" => $v['utmMedium'] , "system_id" => $settings['system_id']));
					if($u){
						$fee = fee($u['uid'],$id);
					}else{
						$fee = fee('000000',$id);
					}
					$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
					if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					$resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "uniacid" => $id , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
					if($resin){
					  orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
					}
				}
			}else{
				$order = pdo_get(MODULE_NAME."_order", array("order_id" => $v['orderId'] , "uniacid" => $id));
				if($order){
					if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
					$fee = fee($order['c_1_uid'],$id);
					if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					pdo_update(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "billingDate" => $v['billingDate'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "uniacid" => $id , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
				}else{
					$u = pdo_get(MODULE_NAME."_user", array("utmMedium" => $v['utmMedium'] , "uniacid" => $id));
					if($u){
						$fee = fee($u['uid'],$id);
					}else{
						$fee = fee('000000',$id);
					}
					$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
					if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
					if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
					if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
					$resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "uniacid" => $id  , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
					if($resin){
					  orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
					}
				}
			}
		}
		if($total_pages > 1){
			for ($x=2; $x<=$total_pages; $x++) {

				$url = "https://union.dianping.com/data/promote/verify/item?timestamp=" . $timestamp . "&requestId=" . $requestId . "&utmSource=" . $utmSource . "&startAddDate=" . urlencode($startAddDate) . "&endAddDate=" . urlencode($endAddDate) . "&page=".$x."&size=50&version=2.0&accessToken=" . $accessToken;
				$res = ihttp_get($url);
				$res = json_decode($res["content"], true);

				if(count($res['msg']['records']) > 0){
					if($v['orderType'] == '团单'){$pingtai_name = '美团团购';}elseif($v['orderType'] == '外卖'){$pingtai_name = '美团外卖';}elseif($v['orderType'] == '闪购'){$pingtai_name = '美团闪购';}elseif($v['orderType'] == '酒店'){$pingtai_name = '美团酒店';}
					foreach ($res['msg']['records'] as $k => $v) {
						if($settings['system_type'] == 1){
							$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => $v['orderId'], "system_id" => $settings['system_id']));
							if($order){
								if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
								$fee = fee($order['c_1_uid'],$id);
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "billingDate" => $v['billingDate'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'], "system_id" => $settings['system_id']));
							}else{
								$u = pdo_get(MODULE_NAME."_user_u", array("utmMedium" => $v['utmMedium'] , "system_id" => $settings['system_id']));
								if($u){
									$fee = fee($u['uid'],$id);
								}else{
									$fee = fee('000000',$id);
								}
								$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								$resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "billingDate" => $v['billingDate'] , "uniacid" => $id , "system_id" => $settings['system_id'] , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
								if($resin){
								  orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
								}
							}
						}else{
							$order = pdo_get(MODULE_NAME."_order", array("order_id" => $v['orderId'] , "uniacid" => $id));
							if($order){
								if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
								$fee = fee($order['c_1_uid'],$id);
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								pdo_update(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "goods_title" => $v['shopName'] , "billingDate" => $v['billingDate'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "uniacid" => $id , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
							}else{
								$u = pdo_get(MODULE_NAME."_user", array("utmMedium" => $v['utmMedium'] , "uniacid" => $id));
								if($u){
									$fee = fee($u['uid'],$id);
								}else{
									$fee = fee('000000',$id);
								}
								$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
								if($v['itemBizStatus'] == 2){$v['itemBizStatus'] = 1;}
								if($v['itemBizStatus'] == 3){$v['itemBizStatus'] = 8;}
								if($v['itemBizStatus'] == 99){$v['itemBizStatus'] = 9;$v['balanceAmount'] = 0;}
								$resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'fenxiao' , "pingtai_name" => $pingtai_name , "order_type" => $v['orderType'] , "order_id" => $v['orderId'] , "order_paid_time" => strtotime($v['orderPayTime']) , "order_price" => $v['actualOrderAmount'] , "order_profit" => $v['balanceAmount'] , "income_rate" => $v['balanceCommissionRatio'] , "billingDate" => $v['billingDate'] , "goods_title" => $v['shopName'] , "goods_img" => $v['shopImage'] , "sid" => $v['promotionId'] , "order_create_time" => strtotime($v['orderPayTime']) , "order_status" => $v['itemBizStatus'] , "uniacid" => $id  , "c_1" => round($v['balanceAmount'] * $fee['c_1_fee'] * $settings['meituan_yjrate']/10000,2) , "c_2" => round($v['balanceAmount'] * $fee['c_2_fee'] * $settings['meituan_yjrate']/10000,2) , "c_3" => round($v['balanceAmount'] * $fee['c_3_fee'] * $settings['meituan_yjrate']/10000,2) , "c_t" => round($v['balanceAmount'] * $fee['c_t_fee'] * $settings['meituan_yjrate']/10000,2), "c_2t" => round($v['balanceAmount'] * $fee['c_2t_fee'] * $settings['meituan_yjrate']/10000,2), "c_1h" => round($v['balanceAmount'] * $fee['c_1h_fee'] * $settings['meituan_yjrate']/10000,2), "c_2h" => round($v['balanceAmount'] * $fee['c_2h_fee'] * $settings['meituan_yjrate']/10000,2), "c_3h" => round($v['balanceAmount'] * $fee['c_3h_fee'] * $settings['meituan_yjrate']/10000,2), "c_4h" => round($v['balanceAmount'] * $fee['c_4h_fee'] * $settings['meituan_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c1_uid" => $fee['c1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid'], "new" => 1));
								if($resin){
									orderNotify_fenxiao($fee,$v,$settings['meituan_yjrate'],$id,$settings['system_id'],$settings);
								}
							}
						}
					}
				}
			}
		}
	}
}


function aesencrypt($data,$key='')
   {
       $base64 = openssl_encrypt($data, 'AES-128-ECB', $key, OPENSSL_RAW_DATA, '');
       return bin2hex($base64);
   }
function orderNotify_fenxiao($fee,$v,$yjrate,$id,$system_id,$settings){
	  if($fee['c_1_uid'] && round($v['balanceAmount'] * $fee['c_1_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_1_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_1_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_1_openid']));
							  $res = xcxneworderNotify($fee['c_1_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_1_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_1_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_1_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_2_uid'] && round($v['balanceAmount'] * $fee['c_2_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2_openid']));
							  $res = xcxneworderNotify($fee['c_2_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_3_uid'] && round($v['balanceAmount'] * $fee['c_3_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_3_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_3_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_3_openid']));
							  $res = xcxneworderNotify($fee['c_3_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_3_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_3_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_3_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_t_uid'] && round($v['balanceAmount'] * $fee['c_t_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_t_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_t_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_t_openid']));
							  $res = xcxneworderNotify($fee['c_t_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_t_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_t_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_t_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_2t_uid'] && round($v['balanceAmount'] * $fee['c_2t_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2t_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2t_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2t_openid']));
							  $res = xcxneworderNotify($fee['c_2t_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2t_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2t_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2t_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_1h_uid'] && round($v['balanceAmount'] * $fee['c_1h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_1h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_1h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_1h_openid']));
							  $res = xcxneworderNotify($fee['c_1h_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_1h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_1h_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_1h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_2h_uid'] && round($v['balanceAmount'] * $fee['c_2h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2h_openid']));
							  $res = xcxneworderNotify($fee['c_2h_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2h_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_3h_uid'] && round($v['balanceAmount'] * $fee['c_3h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_3h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_3h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_3h_openid']));
							  $res = xcxneworderNotify($fee['c_3h_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_3h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_3h_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_3h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_4h_uid'] && round($v['balanceAmount'] * $fee['c_4h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_4h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$settings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderId'], $v['shopName'],$xcxsettings,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['actualOrderAmount'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_4h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_4h_openid']));
							  $res = xcxneworderNotify($fee['c_4h_openid'], $v['orderId'], $v['shopName'],$xcxid['uniacid'],strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_4h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_4h_openid'], $v['orderId'], $v['shopName'],$id,strtotime($v['orderPayTime']),round($v['balanceAmount'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['actualOrderAmount']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_4h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
}

function orderNotify($fee,$v,$yjrate,$id,$system_id,$settings){
	  if($fee['c_1_uid'] && round($v['profit'] * $fee['c_1_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_1_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_1_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_1_openid']));
							  $res = xcxneworderNotify($fee['c_1_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_1_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_1_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_1_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_2_uid'] && round($v['profit'] * $fee['c_2_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2_openid']));
							  $res = xcxneworderNotify($fee['c_2_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_3_uid'] && round($v['profit'] * $fee['c_3_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_3_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_3_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_3_openid']));
							  $res = xcxneworderNotify($fee['c_3_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_3_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_3_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_3_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_t_uid'] && round($v['profit'] * $fee['c_t_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_t_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_t_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_t_openid']));
							  $res = xcxneworderNotify($fee['c_t_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_t_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_t_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_t_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_2t_uid'] && round($v['profit'] * $fee['c_2t_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2t_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2t_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2t_openid']));
							  $res = xcxneworderNotify($fee['c_2t_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2t_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2t_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2t_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_1h_uid'] && round($v['profit'] * $fee['c_1h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_1h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_1h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_1h_openid']));
							  $res = xcxneworderNotify($fee['c_1h_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_1h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_1h_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_1h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_2h_uid'] && round($v['profit'] * $fee['c_2h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2h_openid']));
							  $res = xcxneworderNotify($fee['c_2h_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2h_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_3h_uid'] && round($v['profit'] * $fee['c_3h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_3h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_3h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_3h_openid']));
							  $res = xcxneworderNotify($fee['c_3h_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_3h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_3h_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_3h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_4h_uid'] && round($v['profit'] * $fee['c_4h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_4h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$settings,$v['paytime'],round($v['profit'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['orderid'], $v['smstitle'],$xcxsettings,$v['paytime'],round($v['profit'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['payprice'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_4h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_4h_openid']));
							  $res = xcxneworderNotify($fee['c_4h_openid'], $v['orderid'], $v['smstitle'],$xcxid['uniacid'],$v['paytime'],round($v['profit'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['payprice']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_4h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_4h_openid'], $v['orderid'], $v['smstitle'],$id,$v['paytime'],round($v['profit'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['payprice']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_4h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
}

function neworderNotify($openid, $order_id, $goods_title, $xcxsettings, $paytime, $fee, $price, $id)
{
	global $_GPC;
	global $_W;

	$config = $xcxsettings;
	load()->model('mc');
	if (!empty($id)) {
		$_W["account"] = uni_fetch($id);
	}
	if (empty($_W["account"])) {
		exit("initial error hash or id");
	}
	$account_api = WeAccount::create();
	$token = $account_api->getAccessToken();
	$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=" . $token;
	$post = array();
	$post["touser"] = $openid;
	$order_id = cut_str($order_id, 4, 0).'****'.cut_str($order_id, 4, -4);
	$mp_template_msg = array("appid" => $config["gzh_appid"], "template_id" => $config["gzh_neworder_tplid"], "miniprogram" => array("appid" => $_W["account"]["key"], "pagepath" => "pages/user/index"), "data" => array("first" => array("value" => "又来新订单啦！", "color" => "#173177"), "keyword1" => array("value" => $goods_title, "color" => "#173177"), "keyword2" => array("value" => date("Y-m-d H:i:s",$paytime), "color" => "#173177"), "keyword3" => array("value" => '￥'.$price.' (预估:￥'.$fee.')', "color" => "#173177"), "keyword4" => array("value" => $order_id, "color" => "#173177"), "keyword5" => array("value" => "-", "color" => "#173177"), "remark" => array("value" => "点击本消息可以快速打开小程序。", "color" => "#173177")));
	$post["mp_template_msg"] = $mp_template_msg;
	$res = ihttp_request($url, json_encode($post));
	$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '公众号新订单通知',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($post).json_encode($res)));
	if($res['errcode'] == 0){
		return true;
	}else{
		return false;
	}
}

function xcxneworderNotify($openid, $order_id, $goods_title, $id, $paytime, $fee, $price)
{
	global $_GPC;
	global $_W;
	$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" =>$id));
	$config = unserialize($settings['settings']);
	load()->model('mc');
	if (!empty($id)) {
		$_W["account"] = uni_fetch($id);
	}
	if (empty($_W["account"])) {
		exit("initial error hash or id");
	}
	$account_api = WeAccount::create();
	$token = $account_api->getAccessToken();
	$url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$token;
	$dd = array();
	$dd['touser'] = $openid;
	$order_id = cut_str($order_id, 4, 0).'****'.cut_str($order_id, 4, -4);
	$dd['template_id'] = $config["warn_order_tplid"];
	$dd['page'] = 'pages/user/index';
	$dd['data'] = array(
		$config["warn_order_tplid_1"]=>array(
			"value"=>$order_id
		),
		$config["warn_order_tplid_2"]=>array(
			"value"=>date("Y年m月d日 H:i",$paytime)
		),
		$config["warn_order_tplid_3"]=>array(
			"value"=>'￥'.$price
		),
		$config["warn_order_tplid_4"]=>array(
			"value"=>mb_substr($goods_title,0,20)
		)
	);
	load()->func('communication');
	$res = ihttp_request($url,json_encode($dd));
	
	$res = json_decode($res["content"],true);
	$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '小程序新订单通知',"apiname" => 'xcxneworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($dd).json_encode($res)));
	if($res['errcode'] == 0){
		return true;
	}else{
		return false;
	}
	
}
function cut_str($string, $sublen, $start = 0, $code = 'UTF-8') 
{ 
	if($code == 'UTF-8') 
	{ 
		$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"; 
		preg_match_all($pa, $string, $t_string);
		if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen));
		return join('', array_slice($t_string[0], $start, $sublen));
	}
	else
	{
		$start = $start*2;
		$sublen = $sublen*2;
		$strlen = strlen($string);
		$tmpstr = '';
		for($i=0; $i< $strlen; $i++)
		{
			if($i>=$start && $i< ($start+$sublen))
			{
				if(ord(substr($string, $i, 1))>129)
				{
					$tmpstr.= substr($string, $i, 2);
				}
				else
				{
					$tmpstr.= substr($string, $i, 1);
				}
			}
			if(ord(substr($string, $i, 1))>129) $i++;
		}
		return $tmpstr;
	}
}

function fee($uid,$id)
{
	global $_GPC;
	global $_W;
	$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" =>$id));
	$settings = unserialize($settings['settings']);
	if($settings['system_type'] == 1){
		$u = pdo_get(MODULE_NAME."_user_u", array("uid" => $uid, "system_id" => $settings['system_id']));
	}else{
		$u = pdo_get(MODULE_NAME."_user", array("uid" => $uid , "uniacid" => $id));
	}
	if($u){
		//如果是普通会员
		$t = 0;$h = 0;$h1 = 0;$h2 = 0;$h3 = 0;$h4 = 0;
		if($u['is_tuan'] == 0){
			$c_1_uid = $u['uid'];
			$c_1_openid = $u['openid'];
			$c_1_s1 = $u['s_1_num'];
			$c_1_fee = $settings['c_1'];
			if($u['invite_uid'] != '0'){
				$fa_uid_array = array_reverse(explode("_",$u['invite_uid']));
				$i1 = 1;
				foreach($fa_uid_array as $v){
					if($settings['system_type'] == 1){
						$u1 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v , "system_id" => $settings['system_id']));
					}else{
						$u1 = pdo_get(MODULE_NAME."_user", array("uid" => $v , "uniacid" => $id));
					}
					if($u1['is_tuan'] == 0 && $i1 == 1){//如果是普通会员直推
						$c_2_uid = $u1['uid'];
						$c_2_openid = $u1['openid'];
						$c_2_s1 = $u1['s_1_num'];
						$c_2_fee = $settings['c_2'];
						$i2 = 1;
						foreach($fa_uid_array as $v2){
							if($settings['system_type'] == 1){
								$u2 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v2 , "system_id" => $settings['system_id']));
							}else{
								$u2 = pdo_get(MODULE_NAME."_user", array("uid" => $v2 , "uniacid" => $id));
							}
							if($u2['is_tuan'] == 0 && $i2 == 2){//如果是普通会员间推
								$c_3_uid = $u2['uid'];
								$c_3_openid = $u2['openid'];
								$c_3_s1 = $u2['s_1_num'];
								$c_3_fee = $settings['c_3'];
								$i3 = 1;
								foreach($fa_uid_array as $v3){
									if($settings['system_type'] == 1 && $i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v3 , "system_id" => $settings['system_id']));
									}elseif($i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user", array("uid" => $v3 , "uniacid" => $id));
									}
									if($u3['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0 && $i3 > 2){//团长非直属
										$c_t_uid = $u3['uid'];
										$c_t_openid = $u3['openid'];
										$c_t_s1 = $u3['s_1_num'];
										$c_t_fee = $settings['c_t'];
										$t = 1;
										continue;
									}elseif($u3['is_tuan'] == 1 && $t == 1 && $h == 0 && $h1 == 0  && $i3 > 2){//团长直属团长
										$c_2t_uid = $u3['uid'];
										$c_2t_openid = $u3['openid'];
										$c_2t_s1 = $u3['s_1_num'];
										$c_2t_fee = $settings['c_2t'];
										$t = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $t == 0 && $h == 0 && $h1 == 0 && $i3 > 2){//合伙人非直属会员
										$c_t_uid = $u3['uid'];
										$c_t_openid = $u3['openid'];
										$c_t_s1 = $u3['s_1_num'];
										$c_t_fee = $settings['c_h_3'];
										$h = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $t > 0 && $h == 0 && $h1 == 0 && $i3 > 2){//合伙人直属团队
										$c_1h_uid = $u3['uid'];
										$c_1h_openid = $u3['openid'];
										$c_1h_s1 = $u3['s_1_num'];
										$c_1h_fee = $settings['c_1h'];
										$h = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $t > 0 && $h == 1 && $h1 == 0 && $i3 > 2){//合伙人间属团队
										$c_2h_uid = $u3['uid'];
										$c_2h_openid = $u3['openid'];
										$c_2h_s1 = $u3['s_1_num'];
										$c_2h_fee = $settings['c_2h'];
										$h = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i3 > 2){//合伙人直属合伙人
										$c_3h_uid = $u3['uid'];
										$c_3h_openid = $u3['openid'];
										$c_3h_s1 = $u3['s_1_num'];
										$c_3h_fee = $settings['c_3h'];
										$h1 = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i3 > 2){//合伙人间属合伙人
										$c_4h_uid = $u3['uid'];
										$c_4h_openid = $u3['openid'];
										$c_4h_s1 = $u3['s_1_num'];
										$c_4h_fee = $settings['c_4h'];
										$h1 = 2;
										break;
									}
									$i3++;
								}
								break;
							}elseif($u2['is_tuan'] == 1 && $i2 == 2){//如果是团长间推
								$c_t_uid = $u2['uid'];
								$c_t_openid = $u2['openid'];
								$c_t_s1 = $u2['s_1_num'];
								$c_t_fee = $settings['c_t'];
								$i3 = 1;
								foreach($fa_uid_array as $v3){
									if($settings['system_type'] == 1 && $i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v3 , "system_id" => $settings['system_id']));
									}elseif($i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user", array("uid" => $v3 , "uniacid" => $id));
									}
									if($u3['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0  && $i3 > 2){//团长直属团长
										$c_2t_uid = $u3['uid'];
										$c_2t_openid = $u3['openid'];
										$c_2t_s1 = $u3['s_1_num'];
										$c_2t_fee = $settings['c_2t'];
										$t = 2;
										continue;
									}elseif($u3['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0  && $i3 > 2){//团长直属团长
										$c_1h_uid = $u3['uid'];
										$c_1h_openid = $u3['openid'];
										$c_1h_s1 = $u3['s_1_num'];
										$c_1h_fee = $settings['c_1h'];
										$h = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 0 && $h1 == 0 && $i3 > 2){//合伙人直属团队
										$c_1h_uid = $u3['uid'];
										$c_1h_openid = $u3['openid'];
										$c_1h_s1 = $u3['s_1_num'];
										$c_1h_fee = $settings['c_1h'];
										$h = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 1 && $h1 == 0 && $i3 > 2){//合伙人间属团队
										$c_2h_uid = $u3['uid'];
										$c_2h_openid = $u3['openid'];
										$c_2h_s1 = $u3['s_1_num'];
										$c_2h_fee = $settings['c_2h'];
										$h = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i3 > 2){//合伙人直属合伙人
										$c_3h_uid = $u3['uid'];
										$c_3h_openid = $u3['openid'];
										$c_3h_s1 = $u3['s_1_num'];
										$c_3h_fee = $settings['c_3h'];
										$h1 = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i3 > 2){//合伙人间属合伙人
										$c_4h_uid = $u3['uid'];
										$c_4h_openid = $u3['openid'];
										$c_4h_s1 = $u3['s_1_num'];
										$c_4h_fee = $settings['c_4h'];
										$h1 = 2;
										break;
									}
									$i3++;
								}
								break;
							}elseif($u2['is_tuan'] == 2 && $i2 == 2){//如果是合伙人间推
								$c_t_uid = $u2['uid'];
								$c_t_openid = $u2['openid'];
								$c_t_s1 = $u2['s_1_num'];
								$c_t_fee = $settings['c_h_3'];
								$i3 = 1;
								foreach($fa_uid_array as $v3){
									if($settings['system_type'] == 1 && $i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v3 , "system_id" => $settings['system_id']));
									}elseif($i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user", array("uid" => $v3 , "uniacid" => $id));
									}
									if($u3['is_tuan'] == 2 && $h1 == 0 && $i3 > 2){//合伙人直属合伙人
										$c_3h_uid = $u3['uid'];
										$c_3h_openid = $u3['openid'];
										$c_3h_s1 = $u3['s_1_num'];
										$c_3h_fee = $settings['c_3h'];
										$h1 = 1;
										continue;;
									}
									if($u3['is_tuan'] == 2 && $h1 == 1 && $i3 > 2){//合伙人间属合伙人
										$c_4h_uid = $u3['uid'];
										$c_4h_openid = $u3['openid'];
										$c_4h_s1 = $u3['s_1_num'];
										$c_4h_fee = $settings['c_4h'];
										$h1 = 2;
										break;
									}
									$i3++;
								}
								break;
							}
							$i2++;
						}
						break;
					}elseif($u1['is_tuan'] == 1 && $i1 == 1){//如果是团长直推
						$c_2_uid = $u1['uid'];
						$c_2_openid = $u1['openid'];
						$c_2_s1 = $u1['s_1_num'];
						$c_2_fee = $settings['c_t_2'];
						$i2 = 1;
						foreach($fa_uid_array as $v2){
							if($settings['system_type'] == 1){
								$u2 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v2 , "system_id" => $settings['system_id']));
							}else{
								$u2 = pdo_get(MODULE_NAME."_user", array("uid" => $v2 , "uniacid" => $id));
							}
							if($u2['is_tuan'] == 1 && $t == 0  && $h == 0 && $h1 == 0 && $i2 > 1){//如果是团长间推
								$c_2t_uid = $u2['uid'];
								$c_2t_openid = $u2['openid'];
								$c_2t_s1 = $u2['s_1_num'];
								$c_2t_fee = $settings['c_2t'];
								$t = 2;
								continue;
							}elseif($u2['is_tuan'] == 2 && $t == 0  && $h == 0 && $h1 == 0 && $i2 > 1){//如果是团长间推
								$c_1h_uid = $u2['uid'];
								$c_1h_openid = $u2['openid'];
								$c_1h_s1 = $u2['s_1_num'];
								$c_1h_fee = $settings['c_1h'];
								$h = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 0 && $h1 == 0 && $i2 > 1){//合伙人直属团队
								$c_1h_uid = $u2['uid'];
								$c_1h_openid = $u2['openid'];
								$c_1h_s1 = $u2['s_1_num'];
								$c_1h_fee = $settings['c_1h'];
								$h = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 1 && $h1 == 0 && $i2 > 1){//合伙人间属团队
								$c_2h_uid = $u2['uid'];
								$c_2h_openid = $u2['openid'];
								$c_2h_s1 = $u2['s_1_num'];
								$c_2h_fee = $settings['c_2h'];
								$h = 2;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i2 > 1){//合伙人直属合伙人
								$c_3h_uid = $u2['uid'];
								$c_3h_openid = $u2['openid'];
								$c_3h_s1 = $u2['s_1_num'];
								$c_3h_fee = $settings['c_3h'];
								$h1 = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i2 > 1){//合伙人间属合伙人
								$c_4h_uid = $u2['uid'];
								$c_4h_openid = $u2['openid'];
								$c_4h_s1 = $u2['s_1_num'];
								$c_4h_fee = $settings['c_4h'];
								$h1 = 2;
								break;
							}
							$i2++;
						}
						break;
					}elseif($u1['is_tuan'] == 2 && $i1 == 1){//如果是合伙人直推
						$c_2_uid = $u1['uid'];
						$c_2_openid = $u1['openid'];
						$c_2_s1 = $u1['s_1_num'];
						$c_2_fee = $settings['c_h_2'];
						$i2 = 1;
						foreach($fa_uid_array as $v2){
							if($settings['system_type'] == 1 && $i2 > 1){
								$u2 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v2 , "system_id" => $settings['system_id']));
							}elseif($i2 > 1){
								$u2 = pdo_get(MODULE_NAME."_user", array("uid" => $v2 , "uniacid" => $id));
							}
							if($u2['is_tuan'] == 2 && $h1 == 0 && $i2 > 1){//合伙人直属合伙人
								$c_3h_uid = $u2['uid'];
								$c_3h_openid = $u2['openid'];
								$c_3h_s1 = $u2['s_1_num'];
								$c_3h_fee = $settings['c_3h'];
								$h1 = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h1 == 1 && $i2 > 1){//合伙人间属合伙人
								$c_4h_uid = $u2['uid'];
								$c_4h_openid = $u2['openid'];
								$c_4h_s1 = $u2['s_1_num'];
								$c_4h_fee = $settings['c_4h'];
								$h1 = 2;
								break;
							}
							$i2++;
						}
						break;
					}
					$i1++;
				}
			}
		}elseif($u['is_tuan'] == 1){//如果是团长
			$c_1_uid = $u['uid'];
			$c_1_openid = $u['openid'];
			$c_1_s1 = $u['s_1_num'];
			$c_1_fee = $settings['c_t_1'];
			if($u['invite_uid'] != '0'){
				$fa_uid_array = array_reverse(explode("_",$u['invite_uid']));
				$i1 = 1;
				foreach($fa_uid_array as $v){
					if($settings['system_type'] == 1){
						$u1 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v , "system_id" => $settings['system_id']));
					}else{
						$u1 = pdo_get(MODULE_NAME."_user", array("uid" => $v , "uniacid" => $id));
					}
					if($u1['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0 && $i1 == 1){//如果是团长直推
						$c_2t_uid = $u1['uid'];
						$c_2t_openid = $u1['openid'];
						$c_2t_s1 = $u1['s_1_num'];
						$c_2t_fee = $settings['c_2t'];
						$t = 2;
						continue;
					}elseif($u1['is_tuan'] == 2 && $t == 0 && $h == 0 && $h1 == 0 && $i1 == 1){//如果是合伙人直推
						$c_1h_uid = $u1['uid'];
						$c_1h_openid = $u1['openid'];
						$c_1h_s1 = $u1['s_1_num'];
						$c_1h_fee = $settings['c_1h'];
						$h = 1;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 0 && $h1 == 0 && $i1 > 1){//合伙人直属团队
						$c_1h_uid = $u1['uid'];
						$c_1h_openid = $u1['openid'];
						$c_1h_s1 = $u1['s_1_num'];
						$c_1h_fee = $settings['c_1h'];
						$h = 1;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 1 && $h1 == 0 && $i1 > 1){//合伙人间属团队
						$c_2h_uid = $u1['uid'];
						$c_2h_openid = $u1['openid'];
						$c_2h_s1 = $u1['s_1_num'];
						$c_2h_fee = $settings['c_2h'];
						$h = 2;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i1 > 1){//合伙人直属合伙人
						$c_3h_uid = $u1['uid'];
						$c_3h_openid = $u1['openid'];
						$c_3h_s1 = $u1['s_1_num'];
						$c_3h_fee = $settings['c_3h'];
						$h1 = 1;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i1 > 1){//合伙人间属合伙人
						$c_4h_uid = $u1['uid'];
						$c_4h_openid = $u1['openid'];
						$c_4h_s1 = $u1['s_1_num'];
						$c_4h_fee = $settings['c_4h'];
						$h1 = 2;
						break;
					}
					$i1++;
				}
			}
		}elseif($u['is_tuan'] == 2){//如果是合伙人
			$c_1_uid = $u['uid'];
			$c_1_openid = $u['openid'];
			$c_1_s1 = $u['s_1_num'];
			$c_1_fee = $settings['c_h_1'];
			if($u['invite_uid'] != '0'){
				$fa_uid_array = array_reverse(explode("_",$u['invite_uid']));
				$i1 = 1;
				foreach($fa_uid_array as $v){
					if($settings['system_type'] == 1){
						$u1 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v , "system_id" => $settings['system_id']));
					}else{
						$u1 = pdo_get(MODULE_NAME."_user", array("uid" => $v , "uniacid" => $id));
					}
					if($u1['is_tuan'] == 2 && $h1 == 0 && $i1 > 0){//合伙人直属合伙人
						$c_3h_uid = $u1['uid'];
						$c_3h_openid = $u1['openid'];
						$c_3h_s1 = $u1['s_1_num'];
						$c_3h_fee = $settings['c_3h'];
						$h1 = 1;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h1 == 1 && $i1 > 0){//合伙人间属合伙人
						$c_4h_uid = $u1['uid'];
						$c_4h_openid = $u1['openid'];
						$c_4h_s1 = $u1['s_1_num'];
						$c_4h_fee = $settings['c_4h'];
						$h1 = 2;
						break;
					}
					$i1++;
				}
			}
		}
	}
	$c1_uid = $c_1_uid;
	if(!$c_1_uid || !$c_1_fee){
		$c_1_uid = 0;
		$c_1_openid = '';
		$c_1_s1 = 0;
		$c_1_fee = 0;
	}
	if(!$c_2_uid || !$c_2_fee){
		$c_2_uid = 0;
		$c_2_openid = '';
		$c_2_s1 = 0;
		$c_2_fee = 0;
	}
	if(!$c_3_uid || !$c_3_fee){
		$c_3_uid = 0;
		$c_3_openid = '';
		$c_3_s1 = 0;
		$c_3_fee = 0;
	}
	if(!$c_t_uid || !$c_t_fee){
		$c_t_uid = 0;
		$c_t_openid = '';
		$c_t_s1 = 0;
		$c_t_fee = 0;
	}
	if(!$c_2t_uid || !$c_2t_fee){
		$c_2t_uid = 0;
		$c_2t_openid = '';
		$c_2t_s1 = 0;
		$c_2t_fee = 0;
	}
	if(!$c_1h_uid || !$c_1h_fee){
		$c_1h_uid = 0;
		$c_1h_openid = '';
		$c_1h_s1 = 0;
		$c_1h_fee = 0;
	}
	if(!$c_2h_uid || !$c_2h_fee){
		$c_2h_uid = 0;
		$c_2h_openid = '';
		$c_2h_s1 = 0;
		$c_2h_fee = 0;
	}
	if(!$c_3h_uid || !$c_3h_fee){
		$c_3h_uid = 0;
		$c_3h_openid = '';
		$c_3h_s1 = 0;
		$c_3h_fee = 0;
	}
	if(!$c_4h_uid || !$c_4h_fee){
		$c_4h_uid = 0;
		$c_4h_openid = '';
		$c_4h_s1 = 0;
		$c_4h_fee = 0;
	}
	$fee = array(
		'c1_uid' => $c1_uid,
		'c_1_uid' => $c_1_uid,
		'c_1_openid' => $c_1_openid,
		'c_1_s1' => $c_1_s1,
		'c_1_fee' => $c_1_fee,
		'c_2_uid' => $c_2_uid,
		'c_2_openid' => $c_2_openid,
		'c_2_s1' => $c_2_s1,
		'c_2_fee' => $c_2_fee,
		'c_3_uid' => $c_3_uid,
		'c_3_openid' => $c_3_openid,
		'c_3_s1' => $c_3_s1,
		'c_3_fee' => $c_3_fee,
		'c_t_uid' => $c_t_uid,
		'c_t_openid' => $c_t_openid,
		'c_t_s1' => $c_t_s1,
		'c_t_fee' => $c_t_fee,
		'c_2t_uid' => $c_2t_uid,
		'c_2t_openid' => $c_2t_openid,
		'c_2t_s1' => $c_2t_s1,
		'c_2t_fee' => $c_2t_fee,
		'c_1h_uid' => $c_1h_uid,
		'c_1h_openid' => $c_1h_openid,
		'c_1h_s1' => $c_1h_s1,
		'c_1h_fee' => $c_1h_fee,
		'c_2h_uid' => $c_2h_uid,
		'c_2h_openid' => $c_2h_openid,
		'c_2h_s1' => $c_2h_s1,
		'c_2h_fee' => $c_2h_fee,
		'c_3h_uid' => $c_3h_uid,
		'c_3h_openid' => $c_3h_openid,
		'c_3h_s1' => $c_3h_s1,
		'c_3h_fee' => $c_3h_fee,
		'c_4h_uid' => $c_4h_uid,
		'c_4h_openid' => $c_4h_openid,
		'c_4h_s1' => $c_4h_s1,
		'c_4h_fee' => $c_4h_fee
	);
	return $fee;
	
}